unit FolhaRosto;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, SqlExpr, Provider, RpBase, RpSystem, RpRender, RpRenderPDF,
  RpCon, RpConDS, DB, DBClient, DBLocal, DBLocalS, RpDefine, RpRave,
  Buttons, ExtCtrls, StdCtrls;

type
  TFrmFolhaRosto = class(TForm)
    pnlOpcoes: TPanel;
    gbxIntervalo: TGroupBox;
    pnlBotoes: TPanel;
    btnGerarRelatorio: TBitBtn;
    BtnSair: TBitBtn;
    BitBtn1: TBitBtn;
    BtnGerarPlanilha: TBitBtn;
    pnlCabecalho: TPanel;
    RadioGroup1: TRadioGroup;
    Edit1: TEdit;
    Button1: TButton;
    Edit2: TEdit;
    Edit3: TEdit;
    rdgSeleciona: TRadioGroup;
    edtIntervalo01: TEdit;
    btnIntervalo01: TButton;
    RadioGroup2: TRadioGroup;
    EdtDocumento: TEdit;
    procedure btnIntervalo01Click(Sender: TObject);
    procedure btnGerarRelatorioClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Edit1Exit(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EdtDocumentoExit(Sender: TObject);
    procedure edtIntervalo01Exit(Sender: TObject);
    procedure EdtDocumentoKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmFolhaRosto: TFrmFolhaRosto;

implementation

uses ConModelo, DmGeral, RelFolhaRosto;

{$R *.dfm}

procedure TFrmFolhaRosto.btnIntervalo01Click(Sender: TObject);
var
 Pessoa, CliFor : string;
begin


    CliFor := 'C';
    Pessoa := 'A';
if TfrmConModelo.ConModPessoas(Pessoa,CliFor) then
    if ConsultaZeos then begin
      edtIntervalo01.Text := DtMGeral.CDS_Consulta.FieldByName('Codigo').AsString;
      Edit3.Text := DtMGeral.CDS_Consulta.FieldByName('nome').AsString;
      DtMGeral.CDS_Consulta.Close;
    end
    else begin
      edtIntervalo01.Text := DtMGeral.SQLC_Consulta.FieldByName('Codigo').AsString;
      Edit3.Text := DtMGeral.SQLC_Consulta.FieldByName('nome').AsString;
      DtMGeral.SQLC_Consulta.Close;
    end;
  edtIntervalo01.SetFocus;
end;

procedure TFrmFolhaRosto.btnGerarRelatorioClick(Sender: TObject);
begin

  FrmRelFolhaRosto := TFrmRelFolhaRosto.Create(Self);

  FrmRelFolhaRosto.sqlRel.DataSource := TDataSource.Create( Self );

  FrmRelFolhaRosto.sqlRel.Close;
  FrmRelFolhaRosto.sqlRel.SQLConnection := DtmGeral.ConexaoBanco;;
  FrmRelFolhaRosto.sqlRel.Sql.Text := 'SELECT PES_IDFCOD, PES_ENDERECO, PES_BAIRRO, PES_CIDADE, PES_CPFCNPJ, PES_FONE, PES_CELULAR, PES_NOME FROM PESSOAS WHERE PES_IDFCOD ='+edtIntervalo01.Text;
  FrmRelFolhaRosto.sqlRel.Open;


  FrmRelFolhaRosto.SqlVendedor.DataSource := TDataSource.Create( Self );
  FrmRelFolhaRosto.SqlVendedor.Close;
  FrmRelFolhaRosto.SqlVendedor.SQLConnection := DtmGeral.ConexaoBanco;;
  FrmRelFolhaRosto.SqlVendedor.Sql.Text := 'SELECT USU_CODIGO, USU_NOME FROM USUARIOS WHERE USU_CODIGO ='+Edit1.Text;

  FrmRelFolhaRosto.SqlVendedor.Open;


 {FrmRelFolhaRosto.SqlItem.DataSource := TDataSource.Create( Self );
  FrmRelFolhaRosto.SqlItem.Close;
  FrmRelFolhaRosto.SqlItem.SQLConnection := DtmGeral.ConexaoBanco;;
  FrmRelFolhaRosto.SqlItem.Sql.Text := 'select documento, QUANTIDADE, TOTAL, produto from caixasaida where documento ='+EdtDocumento.Text;

  FrmRelFolhaRosto.SqlItem.Open;}

  FrmRelFolhaRosto.QRLabel10.Caption := FrmFolhaRosto.EdtDocumento.Text;


  FrmRelFolhaRosto.qRepAniversariantes.Preview;
end;

procedure TFrmFolhaRosto.Button1Click(Sender: TObject);
begin
  if TfrmConModelo.ConModUsuarios then
    if ConsultaZeos then begin
      Edit1.Text := DtMGeral.CDS_Consulta.FieldByName('Codigo').AsString;
      Edit2.Text := DtMGeral.CDS_Consulta.FieldByName('nome').AsString;
      DtMGeral.CDS_Consulta.Close;
    end
    else begin
      Edit1.Text := DtMGeral.SQLC_Consulta.FieldByName('Codigo').AsString;
       Edit2.Text := DtMGeral.SQLC_Consulta.FieldByName('nome').AsString;
      DtMGeral.SQLC_Consulta.Close;
    end;
  Edit1.SetFocus;


end;

procedure TFrmFolhaRosto.Edit1Exit(Sender: TObject);
begin
if Edit1.Text <> ''  then
  Begin
   edtIntervalo01.SetFocus;
  End;
end;

procedure TFrmFolhaRosto.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
Edit1.Clear;
edtIntervalo01.Clear;
Edit3.Clear;
Edit2.Clear;
EdtDocumento.Clear;
end;

procedure TFrmFolhaRosto.FormShow(Sender: TObject);
begin
Edit1.SetFocus;
end;

procedure TFrmFolhaRosto.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if (key = VK_escape) then
close;
end;

procedure TFrmFolhaRosto.EdtDocumentoExit(Sender: TObject);
begin
if EdtDocumento.Text = ''  then
  Begin
   ShowMessage('Verifique o numero da Cidade');
    EdtDocumento.SetFocus;
  End
  Else
    Begin
     btnGerarRelatorio.SetFocus;
    end;
End;



procedure TFrmFolhaRosto.edtIntervalo01Exit(Sender: TObject);
begin
if edtIntervalo01.Text <> '' then
 Begin
  EdtDocumento.SetFocus;
 end;
end;

procedure TFrmFolhaRosto.EdtDocumentoKeyPress(Sender: TObject;
  var Key: Char);
begin
Key := AnsiUpperCase(Key)[Length(Key)];
end;

end.
